#include <vector>
#include <iostream>

using namespace std;

class Solution 
{
    void myReverse(vector<int> & nums, int begin, int end)
    {
        while(begin < end)
        {
            int temp = nums[begin];
            nums[begin] = nums[end];
            nums[end] = temp;
            begin++;
            end--;
        }
    }
public:
    void rotate(vector<int>& nums, int k) 
    {
        if(nums.empty())
        {
            return;
        }
        k = k % nums.size();
        myReverse(nums, 0, nums.size() - 1);
        myReverse(nums, 0, k - 1);
        myReverse(nums, k, nums.size() - 1);
    }
};

// 辅助函数：打印数组
void printArray(const vector<int>& nums) 
{
    cout << "[";
    for(int i = 0; i < nums.size(); i++) 
    {
        cout << nums[i];
        if(i < nums.size() - 1) cout << ",";
    }
    cout << "]";
}

int main() 
{
    Solution solution;
    
    // 测试案例1: [1,2,3,4,5,6,7], k = 3
    cout << "测试案例1:" << endl;
    vector<int> nums1 = {1, 2, 3, 4, 5, 6, 7};
    int k1 = 3;
    cout << "输入: nums = ";
    printArray(nums1);
    cout << ", k = " << k1 << endl;
    solution.rotate(nums1, k1);
    cout << "输出: ";
    printArray(nums1);
    cout << endl;
    cout << "期望: [5,6,7,1,2,3,4]" << endl << endl;
    
    // 测试案例2: [-1,-100,3,99], k = 2
    cout << "测试案例2:" << endl;
    vector<int> nums2 = {-1, -100, 3, 99};
    int k2 = 2;
    cout << "输入: nums = ";
    printArray(nums2);
    cout << ", k = " << k2 << endl;
    solution.rotate(nums2, k2);
    cout << "输出: ";
    printArray(nums2);
    cout << endl;
    cout << "期望: [3,99,-1,-100]" << endl << endl;
    
    // 测试案例3: 单个元素
    cout << "测试案例3 (单个元素):" << endl;
    vector<int> nums3 = {1};
    int k3 = 1;
    cout << "输入: nums = ";
    printArray(nums3);
    cout << ", k = " << k3 << endl;
    solution.rotate(nums3, k3);
    cout << "输出: ";
    printArray(nums3);
    cout << endl;
    cout << "期望: [1]" << endl << endl;
    
    // 测试案例4: k = 0
    cout << "测试案例4 (k = 0):" << endl;
    vector<int> nums4 = {1, 2, 3, 4, 5};
    int k4 = 0;
    cout << "输入: nums = ";
    printArray(nums4);
    cout << ", k = " << k4 << endl;
    solution.rotate(nums4, k4);
    cout << "输出: ";
    printArray(nums4);
    cout << endl;
    cout << "期望: [1,2,3,4,5]" << endl << endl;
    
    // 测试案例5: k等于数组长度
    cout << "测试案例5 (k等于数组长度):" << endl;
    vector<int> nums5 = {1, 2, 3, 4};
    int k5 = 4;
    cout << "输入: nums = ";
    printArray(nums5);
    cout << ", k = " << k5 << endl;
    solution.rotate(nums5, k5);
    cout << "输出: ";
    printArray(nums5);
    cout << endl;
    cout << "期望: [1,2,3,4] (轮转一圈回到原位)" << endl << endl;
    
    // 测试案例6: k大于数组长度
    cout << "测试案例6 (k大于数组长度):" << endl;
    vector<int> nums6 = {1, 2, 3};
    int k6 = 5;
    cout << "输入: nums = ";
    printArray(nums6);
    cout << ", k = " << k6 << endl;
    solution.rotate(nums6, k6);
    cout << "输出: ";
    printArray(nums6);
    cout << endl;
    cout << "期望: [2,3,1] (等效于k=2)" << endl << endl;
    
    // 测试案例7: 两个元素
    cout << "测试案例7 (两个元素):" << endl;
    vector<int> nums7 = {1, 2};
    int k7 = 1;
    cout << "输入: nums = ";
    printArray(nums7);
    cout << ", k = " << k7 << endl;
    solution.rotate(nums7, k7);
    cout << "输出: ";
    printArray(nums7);
    cout << endl;
    cout << "期望: [2,1]" << endl << endl;
    
    // 测试案例8: 大k值
    cout << "测试案例8 (大k值):" << endl;
    vector<int> nums8 = {1, 2, 3, 4, 5, 6};
    int k8 = 11;
    cout << "输入: nums = ";
    printArray(nums8);
    cout << ", k = " << k8 << endl;
    solution.rotate(nums8, k8);
    cout << "输出: ";
    printArray(nums8);
    cout << endl;
    cout << "期望: [2,3,4,5,6,1] (等效于k=5)" << endl << endl;
    
    // 测试案例9: 负数数组
    cout << "测试案例9 (负数数组):" << endl;
    vector<int> nums9 = {-1, -2, -3, -4, -5};
    int k9 = 2;
    cout << "输入: nums = ";
    printArray(nums9);
    cout << ", k = " << k9 << endl;
    solution.rotate(nums9, k9);
    cout << "输出: ";
    printArray(nums9);
    cout << endl;
    cout << "期望: [-4,-5,-1,-2,-3]" << endl << endl;
    
    // 测试案例10: 空数组
    cout << "测试案例10 (空数组):" << endl;
    vector<int> nums10 = {};
    int k10 = 3;
    cout << "输入: nums = ";
    printArray(nums10);
    cout << ", k = " << k10 << endl;
    solution.rotate(nums10, k10);
    cout << "输出: ";
    printArray(nums10);
    cout << endl;
    cout << "期望: []" << endl << endl;
    
    return 0;
}